﻿#include "DeathCrawler.h"
#include "../../MirEnvir/Envir.h"
#include "../DelayedAction.h"
#include "../../../Shared/ServerPackets.h"
#include "../MapObject.h"

using namespace Server::MirDatabase;
using namespace Server::MirEnvir;
namespace S = ServerPackets;

namespace Server::MirObjects::Monsters
{

    DeathCrawler::DeathCrawler(MonsterInfo *info) : MonsterObject(info)
    {
    }

    void DeathCrawler::Die()
    {
        MonsterObject::Die();

        DelayedAction tempVar(DelayedType::Die, getEnvir()->getTime() + 500);
        ActionList.push_back(&tempVar);
    }

    void DeathCrawler::ApplyNegativeEffects(PlayerObject *attacker, DefenceType type, unsigned short levelOffset)
    {
        MonsterObject::ApplyNegativeEffects(attacker, type, levelOffset);

        if (getEnvir()->Random->Next(3) == 0)
        {
            S::ObjectEffect *tempVar = new S::ObjectEffect();
            tempVar->ObjectID = ObjectID;
            tempVar->Effect = SpellEffect::DeathCrawlerBreath;
            Broadcast(tempVar);

            PoisonTarget(attacker, 5, 5, PoisonType::Green, 2000);

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar' statement was not added since tempVar was passed to a method or constructor. Handle memory management manually.
        }
    }

    void DeathCrawler::CompleteDeath(std::vector<std::any> &data)
    {
        std::vector<MapObject*> targets = FindAllTargets(1, getCurrentLocation(), false);
        if (targets.empty())
        {
            return;
        }

        for (int i = 0; i < targets.size(); i++)
        {
            PoisonTarget(targets[i], 5, 5, PoisonType::Green, 2000);
        }
    }
}
